home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / matrixc.zip / 3DEX1.C < prev    next >
C/C++ Source or Header  |  1990-05-10  |  2KB  |  111 lines

  1. /* Example of use of 3D routines to rotate cube on X,Y,Z axes */
  2. /* Make using 
  3.    make make3dex.mak */
  4. /* Written by Nigel Salt */
  5.  
  6. #include <3d.h>
  7. #include <graph.h>
  8.  
  9. double dmatA[4][4];
  10. matrix matA={4,4,&dmatA[0][0]};
  11.  
  12. double dmatB[4][4];
  13. matrix matB={4,4,&dmatB[0][0]};
  14.  
  15. double dmatC[4][4];
  16. matrix matC={4,4,&dmatC[0][0]};
  17.  
  18. double dmatD[4][4];
  19. matrix matD={4,4,&dmatD[0][0]};
  20.  
  21. double dmatE[4][4];
  22. matrix matE={4,4,&dmatE[0][0]};
  23.  
  24. double dmatF[4][4];
  25. matrix matF={4,4,&dmatF[0][0]};
  26.  
  27. double dmatG[4][4];
  28. matrix matG={4,4,&dmatG[0][0]};
  29.  
  30. double dmatH[4][4];
  31. matrix matH={4,4,&dmatH[0][0]};
  32.  
  33. double dmatI[4][4];
  34. matrix matI={4,4,&dmatI[0][0]};
  35.  
  36. double dmatJ[4][4];
  37. matrix matJ={4,4,&dmatJ[0][0]};
  38.  
  39. double cubep[8][3]=
  40. {
  41.   1,1,1,
  42.   1,1,-1,
  43.   1,-1,-1,
  44.   1,-1,1,
  45.   -1,1,1,
  46.   -1,1,-1,
  47.   -1,-1,-1,
  48.   -1,-1,1
  49. };
  50. int cubel[12][2]=
  51. {
  52.   0,1,
  53.   1,2,
  54.   2,3,
  55.   3,0,
  56.   4,5,
  57.   5,6,
  58.   6,7,
  59.   7,4,
  60.   0,4,
  61.   1,5,
  62.   2,6,
  63.   3,7
  64. };
  65. object cube=
  66. {
  67.   8.0,12.0,&cubep[0][0],&cubel[0][0]
  68. };
  69.  
  70. double cubep2[8][3];
  71. int cubel2[12][2];
  72. object cube2=
  73. {
  74.   8.0,12.0,&cubep2[0][0],&cubel2[0][0]
  75. };
  76.  
  77. main()
  78. {
  79.   int i,j;
  80.   char buff[80];
  81.   init3d();
  82.   scale3(&matA,25,25,25);
  83.   objtran(&cube,&matA);
  84.  
  85.   for (j=0;j<3;j++)
  86.     {
  87.     rot3(&matA,pi/16,j);
  88.     _settextposition(30,0);
  89.     sprintf(buff,"%c ROT",'X'+j);
  90.     _outtext(buff);
  91.     for (i=0;i<100;i++)
  92.       {
  93.       _setcolor(15);
  94.       objdraw(&cube);
  95.       objcop(&cube,&cube2);
  96.       objtran(&cube,&matA);
  97.       _setcolor(0);
  98.       objdraw(&cube2);
  99.       }
  100.     }
  101.   _setvideomode(_DEFAULTMODE);
  102. }
  103.  
  104. wait()
  105. {
  106.  _settextposition(30,0);
  107.  _outtext("PRESS KEY");
  108.  getch();
  109.  _clearscreen(_GCLEARSCREEN);
  110. }
  111.